package com.cal.utms.action.maintenance;

import java.util.List;

import com.cal.utms.dao.maintenance.ScreenConfirmationDao;
import com.cal.utms.dto.maintenance.ConfirmConfigDto;
import com.cal.utms.entity.ScreenConfirmation;
import com.cal.utms.model.maintenance.ConfirmConfigModel;
import com.opensymphony.xwork2.Action;
import com.opensymphony.xwork2.ActionSupport;
import com.opensymphony.xwork2.ModelDriven;

public class ConfirmConfigAction extends ActionSupport implements ModelDriven<ConfirmConfigDto> {

	private static final long serialVersionUID = 1L;
	ConfirmConfigDto confirmConfigDto = new ConfirmConfigDto();
	
	@Override
	public ConfirmConfigDto getModel() {
		return confirmConfigDto;
	}
	
	public String saveConfirmFields(){
		ScreenConfirmationDao scDao = new ScreenConfirmationDao();
		ConfirmConfigModel ccModel = new ConfirmConfigModel();
		System.out.println("Save Confirm Fields for "+ confirmConfigDto.getScreen());
		scDao.addList(confirmConfigDto.getScreen(), ccModel.mapDtoToSC(confirmConfigDto));
		confirmConfigDto.setSuccess(true);
		return Action.SUCCESS;		
	}
	
	public String getConfirmFields(){
		ScreenConfirmationDao scDao = new ScreenConfirmationDao();
		List<ScreenConfirmation> scList = scDao.getByScreen(confirmConfigDto.getScreen());
		String fields = "";
		for(ScreenConfirmation sc:scList){
			fields = fields+sc.getField()+";";
		}
		confirmConfigDto.setValues(fields);		
		confirmConfigDto.setSuccess(true);
		return Action.SUCCESS;
	}
	
	public String getConfirmLocalFields(){
		ScreenConfirmationDao scDao = new ScreenConfirmationDao();
		List<ScreenConfirmation> scList = scDao.getByScreen(confirmConfigDto.getScreen());
		String fields = "";
		for(ScreenConfirmation sc:scList){
			fields = fields+sc.getLocalField()+";";
		}
		confirmConfigDto.setValues(fields);		
		confirmConfigDto.setSuccess(true);
		return Action.SUCCESS;
	}

}
